package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TVehicleDriverInfo;
import com.ruoyi.system.service.ITVehicleDriverInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车人信息Controller
 * 
 * @author wzy
 * @date 2024-08-30 11:00:55
 */
@RestController
@RequestMapping("/system/vehicledriver")
public class TVehicleDriverInfoController extends BaseController
{
    @Autowired
    private ITVehicleDriverInfoService tVehicleDriverInfoService;

    /**
     * 查询车人信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:vehicledriver:list')")
    @GetMapping("/list")
    public TableDataInfo list(TVehicleDriverInfo tVehicleDriverInfo)
    {
        startPage();
        List<TVehicleDriverInfo> list = tVehicleDriverInfoService.selectTVehicleDriverInfoList(tVehicleDriverInfo);
        return getDataTable(list);
    }

    /**
     * 导出车人信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:vehicledriver:export')")
    @Log(title = "车人信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TVehicleDriverInfo tVehicleDriverInfo)
    {
        List<TVehicleDriverInfo> list = tVehicleDriverInfoService.selectTVehicleDriverInfoList(tVehicleDriverInfo);
        ExcelUtil<TVehicleDriverInfo> util = new ExcelUtil<TVehicleDriverInfo>(TVehicleDriverInfo.class);
        util.exportExcel(response, list, "车人信息数据");
    }

    /**
     * 获取车人信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:vehicledriver:query')")
    @GetMapping(value = "/{vehicleDriverId}")
    public AjaxResult getInfo(@PathVariable("vehicleDriverId") Long vehicleDriverId)
    {
        return success(tVehicleDriverInfoService.selectTVehicleDriverInfoByVehicleDriverId(vehicleDriverId));
    }

    /**
     * 新增车人信息
     */
    @PreAuthorize("@ss.hasPermi('system:vehicledriver:add')")
    @Log(title = "车人信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TVehicleDriverInfo tVehicleDriverInfo)
    {
        tVehicleDriverInfo.setCreateBy(getNickName());
        return toAjax(tVehicleDriverInfoService.insertTVehicleDriverInfo(tVehicleDriverInfo));
    }

    /**
     * 修改车人信息
     */
    @PreAuthorize("@ss.hasPermi('system:vehicledriver:edit')")
    @Log(title = "车人信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TVehicleDriverInfo tVehicleDriverInfo)
    {
        tVehicleDriverInfo.setUpdateBy(getNickName());
        return toAjax(tVehicleDriverInfoService.updateTVehicleDriverInfo(tVehicleDriverInfo));
    }

    /**
     * 删除车人信息
     */
    @PreAuthorize("@ss.hasPermi('system:vehicledriver:remove')")
    @Log(title = "车人信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{vehicleDriverIds}")
    public AjaxResult remove(@PathVariable Long[] vehicleDriverIds)
    {
        return toAjax(tVehicleDriverInfoService.deleteTVehicleDriverInfoByVehicleDriverIds(vehicleDriverIds));
    }

    /**
     * 获取车人信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:vehicledriver:query')")
    @GetMapping(value = "/{vehicleLicenseNumber}")
    public AjaxResult getOneInfo(@PathVariable("vehicleLicenseNumber") String vehicleLicenseNumber)
    {
        return success(tVehicleDriverInfoService.selectTVehicleDriverInfoByVehicleLicenseNumber(vehicleLicenseNumber));
    }
}
